package com.ruoyi.common.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LiuXiaoYu
 * @date 2021/10/12- 10:27
 */
@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
       // DataPermissionInterceptor dataPermissionInterceptor = new DataPermissionInterceptor();
        //MyBatisPlusDataPermissionHandler myDataPermissionHandler = new MyBatisPlusDataPermissionHandler ();
        // 添加自定义的数据权限处理器
       // dataPermissionInterceptor.setDataPermissionHandler(myDataPermissionHandler);
        //interceptor.addInnerInterceptor(dataPermissionInterceptor);
        //添加分页拦截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        //防止全表更新与删除插件: BlockAttackInnerInterceptor
        BlockAttackInnerInterceptor blockAttackInnerInterceptor = new BlockAttackInnerInterceptor();
        interceptor.addInnerInterceptor(blockAttackInnerInterceptor);
        return interceptor;
    }


}
